<?php echo $this->render('layouts/__header.phtml'); ?><?php echo $this->render('layouts/__nav.phtml'); ?>
<style>
<!--
div#engineerlist,#statuslist,#propertylist{
	display:none;
}
label.chooselist {
	width:165px;
	display:block;
	float:left;
	padding:5px 0px;
}
div.choosemenu{
	clear:both;
	text-align:right;
	padding-right:10px;
}
div.choosetab{
	width:100%;
	height:25px;
	clear:both;
	border-bottom:solid #f4f4f4 1px;	
	margin:5px 0px;
}

div.chooselink{
	float:left; 
	padding:5px 10px;
	width:120px;
	background-color:#f4f4f4;font-weight:bold
}

#engineerselected, #propertyselected, #statusselected {
	float:right;
	padding:5px 10px;
}
-->
</style>
<script type="text/javascript" src="/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/js/calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar/calendar-setup.js"></script>
<style type="text/css">
@import url(/js/calendar/calendar.css); 
</style>
<script type="text/javascript" src="/js/rpt/swfobject.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){	
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"calendarBeginButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"calendarEndButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"vBeginDate",singleClick:true,step:1});
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"vEndDate",singleClick:true,step:1});
	changeData();	
});	

var engineers = "";
var statuss = "";
var propertys = "";
function changeData(){
	var request_uri = '/report/rptdataewe/show/list';
	request_uri += '/dates/'+$('date_start').value+'/datee/'+$('date_end').value;	
	request_uri += '/dimension/'+$('dimension').value; 
	if (engineers != "") request_uri += "/engineers/" + engineers;
	if (statuss != "") request_uri += "/statuss/" + statuss;
	if (propertys != "") request_uri += "/propertys/" + propertys;
		 
	$('loadingbox').setStyle('display', 'block');	
	new Ajax(request_uri, {
		method: 'get',
		evalScripts : true,		
		update: $('listing'),
		onComplete: function(){
			$('loadingbox').setStyle('display', 'none');			
			$('listing').setStyle('display', 'block');
		}
	}).request();
}

function setData(request_uri) {
	   var flashMovie;
	   flashMovie = document.getElementById("amrpt");
	      if (flashMovie) {      
	      new Ajax(request_uri, {
			method: 'get',
			evalScripts : true,		
			onComplete: function(){						
				flashMovie.setData(this.response.text);
				
			}
		}).request(); 
      }
}

function chooseShow(type) {
	var types = type+"s";
	var typel = type+"list";
	PopBox.pop(document.getElementById(typel).innerHTML);
	eval("var choosed = ','+" + types + "+','");
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (choosed.indexOf(","+item.value+",") != -1) {
			item.checked = true;
		}
	});
}

function chooseOK(type) {
	var types = type+"s";
	var html = "";
	eval(types + "= '';");	
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (item.checked) {
			eval(types + " += ',' + item.value;");
			var pitem = item.parentNode;
			item.remove();
			html += "<label id='"+type+item.value+"' style='margin:0px 5px;'>"
			     +		pitem.innerHTML
				 +  "	[<a href='#' onclick='chooseRemove(\""+type+"\","+item.value+")'><img src='/images/icon_no.gif' /></a>]"
				 +  "</label>";
		}
	});
	eval(types + "=" + types + ".substring(1);"); //delete first ","	
	$(type+"selected").innerHTML = html;
	PopBox.close();
	changeData();
}

function chooseRemove(type,value) {
	types = type + "s";
	eval("var choosed = ','+" + types + "+',';");
	eval(types + "=trimComma(choosed.replace(',' + value + ',', ','))");
	eval("$('"+type+value+"').remove();");
	changeData();
}

function trimComma(str) {
	return str.replace(/(^,*)|(,*$)/g, "");
}
</script>
<div style="text-align:right;width:100%;"> Dimension:&nbsp;
    <select id="dimension" onchange="changeData();">
        <option value='engineer'>Engineer</option>
        <option value='property'>Site</option>
        <option value='pm'>PM</option>
        <option value='status'>Status</option>
    </select>
</div>
<div style="margin:10px 0;">
	<h2>Select date range for the report:</h2>
	<span class="left" style="padding-right:10px;">Start Date &nbsp;
	<input id="date_start" name="date_start" value="<?php if (isset($this->task['date_start'])) echo $this->task['date_start']; else echo date("Y-m-d"); ?>" style="width: 80px;" type="text" readonly />
	<input type="button" id="calendarBeginButton" class="cal" style="width:20px" />
	</span> <span class="left">End Date &nbsp;
	<input id="date_end" name="date_end" value="<?php if (isset($this->task['date_end'])) echo $this->task['date_end']; else echo date("Y-m-d"); ?>" style="width: 80px;" type="text" readonly />
	<input type="button" id="calendarEndButton" class="cal" style="width:20px" />
	</span> &nbsp;&nbsp;
	<input type="button" value="check report!" onClick="changeData()">
	<!-- choose engineer begin -->
	<div id="engineerlist">
		<div>
			<?php foreach($this->engineerList as $engineer): ?>
			<label class="chooselist">
			<input type="checkBox" name="engineer" value="<?php echo $engineer["id"] ?>">
			<?php echo $engineer['name']?></label>
			<?php endforeach; ?>
		</div>
		<div class="choosemenu">
			<input type="button" value="Ok" onclick="chooseOK('engineer')">
		</div>
	</div>
	<!-- choose engineer end -->
	<!-- choose status begin -->
	<div id="statuslist">
		<div>
			<?php foreach($this->statusList as $key=>$status): ?>
			<label class="chooselist">
			<input type="checkBox" name="engineer" value="<?php echo $key ?>">
			<?php echo $status?></label>
			<?php endforeach; ?>
		</div>
		<div class="choosemenu">
			<input type="button" value="Ok" onclick="chooseOK('status')">
		</div>
	</div>
	<!-- choose status end -->
	<!-- choose property begin -->
	<div id="propertylist">
		<div>
			<?php foreach($this->propertyList as $key=>$property): ?>
			<label class="chooselist">
			<input type="checkBox" name="engineer" value="<?php echo $key ?>">
			<?php echo $property?></label>
			<?php endforeach; ?>
		</div>
		<div class="choosemenu">
			<input type="button" value="Ok" onclick="chooseOK('property')">
		</div>
	</div>
	<!-- choose property end -->
	<br />
	<div class="choosetab">
		<div class='chooselink'><a href="#" onclick="return chooseShow('engineer');">Choose Engineer</a></div>
		<div id="engineerselected"></div>
	</div>
	<div class="choosetab">
		<div class='chooselink'><a href="#" onclick="return chooseShow('status');">Choose Status</a></div>
		<div id="statusselected"></div>
	</div>
	<div class="choosetab">
		<div class='chooselink'><a href="#" onclick="return chooseShow('property');">Choose Property</a></div>
		<div id="propertyselected"></div>
	</div>
</div>
<div class="cl"></div>
<h2 style="margin-top:20px;">Task Listing:</h2>
<div id="listing" style="display:none;"> </div>
<div id="loadingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Loading ...</b></div>
<?php echo $this->render('layouts/__footer.phtml'); ?>